/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.punishinform.controller;

import com.icinfo.cloud.common.core.Validator.BaseGroup;
import cn.hutool.core.util.ObjectUtil;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.ucase.punishinform.dto.*;
import com.icinfo.cloud.provider.punish.ucase.punishinform.service.ICaseCollectiveDiscussService;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.CaseCollectiveDiscusSproposalVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.CaseCollectiveDiscussSignStatusInfoVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.CaseCollectiveDiscussUserListVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.CaseCollectiveDiscussVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 描述:  集体议案 case_collective_discuss 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年02月17日
 */
@RestController
@RequestMapping("/punish/inform/caseCollectiveDiscuss")
public class CaseCollectiveDiscussController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseCollectiveDiscussController.class);

    @Autowired
    private ICaseCollectiveDiscussService caseCollectiveDiscussService;

    /**
     * 【V1.0.0】描述：根据案件id获取集体议案信息
     *
     * @param request
     * @return {@link Result<CaseCollectiveDiscussVo>}
     * @author liyafeng
     * @date 2022/2/17
     */
    @PostMapping("/getCaseCollectiveDiscussBaseInfoVo")
    public Result<CaseCollectiveDiscussVo> getCaseCollectiveDiscussBaseInfo(@RequestBody @Validated(BaseGroup.Query.class) InformHtmlRequest request) {
        return Result.success(caseCollectiveDiscussService.getCaseCollectiveDiscussBaseInfo(request));
    }

    /**
     * 【V1.0.0】描述：保存并生成集体议案文书
     *
     * @param caseCollectiveDiscussDto
     * @return {@link Result<String>}
     * @author liyafeng
     * @date 2022/2/17
     */
    @PostMapping("/saveCaseCollectiveDiscussBaseInfo")
    public Result<Map<String, Object>> saveCaseCollectiveDiscuss(@RequestBody CaseCollectiveDiscussDto caseCollectiveDiscussDto) {
        Map<String, Object> resultMap = caseCollectiveDiscussService.saveCaseCollectiveDiscuss(caseCollectiveDiscussDto);
        if (ObjectUtil.isEmpty(resultMap)) {
            return Result.error("保存失败");
        }
        return Result.success("保存成功",resultMap);
    }
    /**
     * 【V1.9.3】描述：用户选择列表
     *
     * @param caseId
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @GetMapping("/collectiveDiscussUserSelect")
    public Result<CaseCollectiveDiscussUserListVo> collectiveDiscussUserSelect(@RequestParam String caseId) {
        CaseCollectiveDiscussUserListVo result = caseCollectiveDiscussService.collectiveDiscussUserSelect(caseId);
        return Result.success("查询成功",result);
    }
    /**
     * 【V1.9.3】描述：发布线上集体议案任务
     *
     * @param dto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping("/saveCaseCollectiveDiscussOnLineTask")
    public Result<Map<String, Object>> saveCaseCollectiveDiscussTask(@RequestBody @Validated CaseCollectiveDiscussUserListDto dto) {
        Map<String, Object> resultMap = caseCollectiveDiscussService.saveCaseCollectiveDiscussTask(dto);
        if (ObjectUtil.isEmpty(resultMap)) {
            return Result.error("保存失败");
        }
        return Result.success("保存成功",resultMap);
    }
    /**
     * 【V1.9.3】描述：获取集体议案分页列表
     *
     * @param pageRequest 页面请求
     * @return {@link Result< PageResponse < CaseCollectiveDiscussVo >> }
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping(value = "/getCaseCollectiveDiscussList")
    public Result<PageResponse<CaseCollectiveDiscussVo>> getCaseCollectiveDiscussList(@RequestBody @Validated CaseCollectiveDiscussPageRequest pageRequest) {
        try {
            List<CaseCollectiveDiscussVo> voList= caseCollectiveDiscussService.getCaseCollectiveDiscussList(pageRequest);
            return Result.success(new PageResponse<>(voList));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    /**
     * 【V1.9.3】描述：获取集体议案人员建议列表
     *
     * @param pageRequest 页面请求
     * @return {@link Result<List<CaseCollectiveDiscussVo >> }
     * @author wuzhihui
     * @date 2022/12/07
     */
    @PostMapping(value = "/getPersonProposalList")
    public Result<List<CaseCollectiveDiscusSproposalVo>> getPersonProposalList(@RequestBody @Validated CaseCollectiveDiscussPersonRequest pageRequest) {
        try {
            List<CaseCollectiveDiscusSproposalVo> voList= caseCollectiveDiscussService.getPersonProposalList(pageRequest);
            return Result.success(voList);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    /**
     * 【V1.9.3】描述：发表议案建议
     *
     * @param dto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping("/saveProposal")
    public Result<CaseCollectiveDiscussUserListVo> saveProposal(@RequestBody @Validated ProposalSaveDto dto) {
        boolean isSuccess = caseCollectiveDiscussService.saveProposal(dto);
        return isSuccess ? Result.success("保存成功") : Result.error("保存失败");
    }
    /**
     * 【V1.9.3】描述：集体议案文书签字确认
     *
     * @param signDto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping("/signConfirm")
    public Result<Map<String, Object>> signConfirm(@RequestBody @Validated CaseCollectiveDiscussSignDto signDto) {
        Map<String, Object> resultMap = caseCollectiveDiscussService.signConfirm(signDto);
        if (ObjectUtil.isEmpty(resultMap)) {
            return Result.error("签字失败");
        }
        return Result.success("签字成功",resultMap);
    }

    /**
     * 【V1.9.3】描述：删除集体议案
     *
     * @param dto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping("/deleteDiscuss")
    public Result<CaseCollectiveDiscussSignStatusInfoVo> deleteDiscuss(@RequestBody @Validated CaseCollectiveDiscussDelDto dto) {
        int counr = caseCollectiveDiscussService.deleteDiscuss(dto);
        return counr > 0 ? Result.success("删除成功") : Result.error("删除失败");
    }
    /**
     * 【V1.9.3】描述：获取文书签字信息（用户判断当前用户是否需要签字）
     *
     * @param signDto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping("/getSignStatusInfo")
    public Result<CaseCollectiveDiscussSignStatusInfoVo> getSignStatusInfo(@RequestBody @Validated CaseCollectiveDiscussSignDto signDto) {
        CaseCollectiveDiscussSignStatusInfoVo vo = caseCollectiveDiscussService.getSignStatusInfo(signDto);
        return Result.success("查询成功",vo);
    }


}
